package com.sxt.business.controller;


import java.util.Date;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.sxt.business.domain.Salesback;
import com.sxt.business.service.ISalesbackService;
import com.sxt.business.vo.SalesbackVO;
import com.sxt.system.domain.User;
import com.sxt.system.utils.DataGridView;
import com.sxt.system.utils.ResultObj;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 俊哥
 * @since 2019-11-16
 */
@RestController
@RequestMapping("salesback")
public class SalesbackController {

	@Autowired
	private ISalesbackService salesbackService;
	
	private Log log = LogFactory.getLog(SalesbackController.class);
	/**
	 * 	添加
	 */
	@RequestMapping("addSalesback")
	public ResultObj addSalesback(Salesback salesback,HttpSession session) {
		try {
			//获取user
			User user = (User) session.getAttribute("user");
			salesback.setOperateperson(user.getName());
			salesback.setSalesbacktime(new Date());
			this.salesbackService.addSalesback(salesback);
			return ResultObj.ADD_SUCCESS;
		} catch (Exception e) {
			log.error("添加错误");
			return ResultObj.ADD_ERROR;
		}
	}
	
	/**
	 * 	查询进货单是否有退货记录
	 */
	@RequestMapping("loadSalesbackBySalesId")
	public DataGridView loadSalesbackBySalesId(Integer salesid) {
		Integer count = this.salesbackService.loadSalesbackBySalesId(salesid);
		return new DataGridView(count);
	}
	
	/**
	 * 全查询退货信息
	 */
	@RequestMapping("loadAllSalesback")
	public DataGridView loadAllSalesback(SalesbackVO salesbackVO) {
		return this.salesbackService.queryAllSalesback(salesbackVO);
	}
}

